﻿using Microsoft.VisualStudio.Text;
using VSAdditionalCommands.ToolWindows.ReplaceKeepCaseToolWindow;

namespace VSAdditionalCommands
{
    /// <summary>
    /// заменить слово или фразу, оставляя регистр первой буквы заменяемого слова
    /// </summary>
    [Command(PackageIds.ReplaceKeepCaseToolWindowCommand)]
    internal sealed class ReplaceKeepCaseToolWindowCommand : BaseCommand<ReplaceKeepCaseToolWindowCommand>
    {
        protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)
        {
            await Package.JoinableTaskFactory.SwitchToMainThreadAsync();
            Package.JoinableTaskFactory.RunAsync(async delegate
            {
                ToolWindowPane window = await Package.ShowToolWindowAsync(typeof(ReplaceKeepCaseToolWindow), 0, true, Package.DisposalToken);
                if ((null == window) || (null == window.Frame))
                {
                    throw new NotSupportedException("Cannot create tool window");
                }
            });
        }
    }
}
